<?php
namespace app\index\controller;
use app\index\controller\Common;
use think\Db;

class Index extends Common
{
    public function index()
    {
        $case = Db::name('case')->limit(1)->order('cid asc')->find();
        $case_type = Db::name('nav')->where('sid',3)->limit(2)->select();
        $person = Db::name('team')->limit(5)->select();
        foreach($person as $key => $per){
            $per_arr[$key]['tid'] = $per['tid'];
            $per_arr[$key]['title'] = $per['title'];
            $per_arr[$key]['intro'] = mb_substr($per['intro'], 0, 120);
            $per_arr[$key]['img_url'] = $per['img_url'];
            $per_arr[$key]['name'] = $per['name'];
        }

        $banner = Db::name('banner')->where('is_show',1)->field('img_url,link_url')->select();
        $news = Db::name('news')->limit(3)->order('mid desc')->select();
        foreach($news as $key => $per){
            $new_arr[$key]['mid'] = $per['mid'];
            $new_arr[$key]['title'] = $per['title'];
            $new_arr[$key]['content'] = mb_substr($per['content'], 0, 50);
            $new_arr[$key]['img_url'] = $per['img_url'];
            $new_arr[$key]['pubtime'] = $per['pubtime'];
        }

        $new_type = Db::name('nav')->where('sid',6)->limit(2)->select();

        $data = [
            'case' => $case,
            'person' => $per_arr,
            'news' => $new_arr,
            'new_type' => $new_type,
            'case_type' => $case_type,
            'banner' => $banner,
        ];
        $this->assign('index', $data);
        return $this->fetch();
    }
}
